
package com.lizhen.behaviorpattern.iteratorpattern.impl;

import com.lizhen.behaviorpattern.iteratorpattern.Container;
import com.lizhen.behaviorpattern.iteratorpattern.Iterator;

public class NameRepository implements Container {
    public String[] names = new String[]{"Robert", "John", "Julie", "Lora"};

    public NameRepository() {
    }

    /*    public Iterator getIterator() {
            return new NameRepository.NameIterator((NameRepository.NameIterator)null);
        }*/

    public Iterator getIterator() {
        return new NameRepository.NameIterator();
    }

    private class NameIterator implements Iterator {
        int index;

        private NameIterator() {
        }

        public boolean hasNext() {
            return this.index < NameRepository.this.names.length;
        }

        public Object next() {
            return this.hasNext() ? NameRepository.this.names[this.index++] : null;
        }
    }
}
